package netWorkPrograming.tcp.tcp04;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.SocketException;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/5/27
 */
public class ReaderThread implements Runnable {
    private Socket socket;
    public ReaderThread(Socket socket) {
        this.socket = socket;
    }
    @Override
    public void run() {
        try(BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        ) {
            String s=null;
            while ((s = br.readLine()) != null) {
                if(s.equals("exit")){
                    System.out.println("退出！");
                    break;
                }
                System.out.println(socket.getRemoteSocketAddress()+"\t:"+s);
            }
        }catch (SocketException e){
            System.out.println("我退了！");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
